/*******************************************************************************
  * @file                   main.c
  * @Author:                MQjehovah                 mail:MQjehovah@hotmail.com
  * @version                1.0.0
  * @date                   2017.8.24
  * @brief                  
  ******************************************************************************
  * @attention
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "delay.h"
#include "LED.h"
#include "GPIO.h"
#include "USART.h"
#include "ring_buffer.h"
#include "shell.h"
#include "stdlib.h"
/* Definition ----------------------------------------------------------------*/
/* Functions -----------------------------------------------------------------*/
/*******************************************************************************
  * @brief  时钟配置            
  * @param  None              
  * @retval None              
  * @Note   None              
*******************************************************************************/
void RCC_Config()
{
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_USART1, ENABLE);
    // RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2| RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4, ENABLE);
}

/*******************************************************************************
  * @brief  中断优先级配置            
  * @param  None              
  * @retval None              
  * @Note   None              
*******************************************************************************/
void NVIC_Config(void) //配置中断优先级
{
    NVIC_InitTypeDef NVIC_InitStructure;

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

    NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    // NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
    // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
    // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    // NVIC_Init(&NVIC_InitStructure);
}
/*******************************************************************************
  * @brief  主函数              
  * @param  None              
  * @retval None              
  * @Note   None              
*******************************************************************************/
int main(void)
{
    int i;
    RCC_Config();
    NVIC_Config();
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); //关闭jtag，保留swd。
    SysTick_init();
    // LED_init();
    // LED_Flash(0, 100, 2);
    USART_Config(USART1, 115200);
    USART_SendStr(USART1, "\r\n");
    USART_SendStr(USART1, " _                 _   _                 _\r\n");
    USART_SendStr(USART1, "| |__   ___   ___ | |_| | ___   __ _  __| | ___ _ __\r\n");
    USART_SendStr(USART1, "| '_ \\ / _ \\ / _ \\| __| |/ _ \\ / _` |/ _` |/ _ \\ '__|\r\n");
    USART_SendStr(USART1, "| |_) | (_) | (_) | |_| | (_) | (_| | (_| |  __/ |\r\n");
    USART_SendStr(USART1, "|_.__/ \\___/ \\___/ \\__|_|\\___/ \\__,_|\\__,_|\\___|_|\r\n");

    u8 BOOTDELAY = 1;
    while (BOOTDELAY--)
    {
        USART_SendStr(USART1, "\rpress any key into bootloader  ");
        USART_SendChar(USART1, BOOTDELAY + 0x30);
        delay_ms(1000);
    }
    USART_SendStr(USART1, "\rJUMPING INTO APPLICATION......\r\n");

    char buf[64];
    while (1)
    {
        char *cmd = shell_readline(buf);
        shell_process(cmd);
        simple_delay_ms(100);
    }
}
/*********************************END OF FILE**********************************/
